/**
 * 
 */
package com.deyou.util;

import android.content.Context;
import android.text.TextUtils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.TimeZone;

/**
 * 日期转换类
 * 
 * @author Administrator
 *
 */
public class DateUtil {
	private static final long ONE_MINUTE = 60;
	private static final long ONE_HOUR = 3600;
	private static final long ONE_DAY = 86400;
	private static final long ONE_MONTH = 2592000;
	private static final long ONE_YEAR = 31104000;

	public static Calendar calendar = Calendar.getInstance();

	public static final SimpleDateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static final SimpleDateFormat DATE_FORMAT_DATE = new SimpleDateFormat("yyyy-MM-dd");
	private static long _DAY_M = 24 * 60 * 60 * 1000;
	private static final String DEFAULT_DATE = "2011-10-10 12:00:00";

	private static String mYear; // 当前年
	private static String mMonth; // 月
	private static String mDay;
	private static String mWay;

	/**
	 * 根据传入的日期转换时间显示 格式如: 周一7月19日
	 * 
	 * @param date
	 */
	public static String parseDate(String date) {
		String parseDate = "";
		if (!TextUtils.isEmpty(date)) {
			parseDate = getDateIndex(date) + getMonthAndDay(date);
		}
		return parseDate;
	}
	/**
	 * 获取明天日期
	 * @param format
	 * @return
	 */
	public static String getYesterday(String format) {
		Date date = new Date();
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		calendar.add(calendar.DATE, -1);//把日期减一天
		date = calendar.getTime();
		SimpleDateFormat sdf2 = new SimpleDateFormat(format);
		String endtime = sdf2.format(date);
		return endtime;
	}
	/**
	 * 获取今天日期
	 * @param format
	 * @return
     */
	public static String getToday(String format) {
		SimpleDateFormat df = new SimpleDateFormat(format);
		return df.format(new Date());
	}

	/**
	 * 获取明天日期
	 * @param format
	 * @return
     */
	public static String getTomorry(String format) {
		Date date = new Date();
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		calendar.add(calendar.DATE, 1);//把日期往后增加一天.整数往后推,负数往前移动
		date = calendar.getTime();
		SimpleDateFormat sdf2 = new SimpleDateFormat(format);
		String endtime = sdf2.format(date);
		return endtime;
	}

	/**
	 * 获取大后天日期
	 * @param format
	 * @return
	 */
	public static String get3DaysLater(String format) {
		Date date = new Date();
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		calendar.add(calendar.DATE, 3);//把日期往后增加一天.整数往后推,负数往前移动
		date = calendar.getTime();
		SimpleDateFormat sdf2 = new SimpleDateFormat(format);
		String endtime = sdf2.format(date);
		return endtime;
	}

	public static Date toDate(String sdate, SimpleDateFormat dateFormater) {
		try {
			return dateFormater.parse(sdate);
		} catch (Exception e) {
			return null;
		}
	}

	/**
	 * 根据传入的时间，判断当天星期几
	 * 
	 * @param ptime
	 * @return
	 */
	public static String getWeedDayByTime(String ptime) {
		String week = "周";
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Calendar c = Calendar.getInstance();
		try {
			c.setTime(format.parse(ptime));
		} catch (ParseException e) {

		}
		final int res = c.get(Calendar.DAY_OF_WEEK);
		switch (res) {
		case 1:
			week += "日";
			break;
		case 2:
			week += "一";
			break;
		case 3:
			week += "二";
			break;
		case 4:
			week += "三";
			break;
		case 5:
			week += "四";
			break;
		case 6:
			week += "五";
			break;
		case 7:
			week += "六";
			break;
		}
		return week;
	}

	/**
	 * 根据传入的时间，判断当天星期几
	 * 显示英文周几
	 * @param ptime
	 * @return
	 */
	public static String getEngWeekDayByTime(String ptime) {
		String week = "";
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Calendar c = Calendar.getInstance();
		try {
			c.setTime(format.parse(ptime));
		} catch (ParseException e) {

		}
		final int res = c.get(Calendar.DAY_OF_WEEK);
		switch (res) {
			case 1:
				week = "Sun";
				break;
			case 2:
				week = "Mon";
				break;
			case 3:
				week = "Tue";
				break;
			case 4:
				week = "Wed";
				break;
			case 5:
				week = "Thu";
				break;
			case 6:
				week = "Fri";
				break;
			case 7:
				week = "Sat";
				break;
		}
		return week;
	}

	/**
	 * 返回月/日
	 * 
	 * @param dealDate
	 * @return
	 */
	public static String getMonthAndDay(String dealDate) {
		String monthDay = "";
		String month = getMonth(dealDate);
		String day = getDay(dealDate);
//		if (!TextUtils.isEmpty(month) && month.length() == 2) {
//			if (month.substring(0, 1).equals("0")) {
//				month = month.substring(1, 2);
//			}
//		}
//		if (!TextUtils.isEmpty(day) && day.length() == 2) {
//			if (day.substring(0, 1).equals("0")) {
//				day = day.substring(1, 2);
//			}
//		}
		monthDay = month + "/" + day + "";
		return monthDay;
	}

	/**
	 * 返回月/日
	 *
	 * @param dealDate
	 * @return
	 */
	public static String getMonthAndDay1(String dealDate) {
		String monthDay = "";
		String month = getMonth(dealDate);
		String day = getDay(dealDate);
		monthDay = month + "月" + day + "日";
		return monthDay;
	}

	/**
	 * 获取日期索引
	 * 
	 * @param date
	 * @return
	 */
	public static String getDateIndex(String date) {
		String week = "";
		if (!TextUtils.isEmpty(date)) {
			long d = getDays(new Date(), string2Date10(date));
			if (0 == Math.abs(d)) {
				week = "今天";
			} else {
				week = getWeedDayByTime(date);
			}
		}
		return week;
	}

	public static Date string2Date10(String date) {
		date = TextUtils.isEmpty(date) ? DEFAULT_DATE : date;
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		format.setTimeZone(TimeZone.getTimeZone("GMT+8"));
		Date d = null;
		try {
			d = format.parse(date);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return d;
	}

	public static String date2StringByFormay(Date date, String formater) {
		if (null == date) {
			return DEFAULT_DATE;
		}
		SimpleDateFormat d = new SimpleDateFormat(formater);
		String time = d.format(date);
		return time;
	}


	public static String date2String10(Date date) {
		if (null == date) {
			return DEFAULT_DATE;
		}
		SimpleDateFormat d = new SimpleDateFormat("yyyy-MM-dd");
		String time = d.format(date);
		return time;
	}

	public static long getDays(Date date1, Date date2) {
		String date1_10 = date2String10(date1);
		String date2_10 = date2String10(date2);
		if (date1_10.equals(date2_10)) {
			return 0;
		}
		date1 = string2Date10(date1_10);
		date2 = string2Date10(date2_10);
		return (date2.getTime() - date1.getTime()) / (_DAY_M);
	}

	private static String getMonth(String dealDate) {
		String month = "";
		if (!TextUtils.isEmpty(dealDate) && dealDate.length() >= 10) {
			month = dealDate.substring(5, 7);
		}
		return month;
	}

	private static String getDay(String dealDate) {
		String day = "";
		if (!TextUtils.isEmpty(dealDate) && dealDate.length() >= 10) {
			day = dealDate.substring(8, 10);
		}
		return day;
	}

	/**
	 * 获取时分秒
	 * @return
     */
	public static String getHourMinSec(String dealDate){
		String hourMinSec = "";
		if (!TextUtils.isEmpty(dealDate) && dealDate.length() >= 18){
			hourMinSec = dealDate.replace(dealDate.substring(0, 11), "").substring(0,5);
		}
		return hourMinSec;
	}

	/**
	 * 获取当前日期N天后的日期
	 * 
	 * @param n
	 * @return
	 */
	public static Date getAfterDate(int n) {
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.DAY_OF_MONTH, n);
		return calendar.getTime();
	}

	/**
	 * 
	 * @return yyyy-mm-dd 2012-12-25
	 */
	public static String getDate() {
		return getYear() + "-" + getMonth() + "-" + getDay();
	}

	/**
	 * @param format
	 * @return yyyy年MM月dd HH:mm MM-dd HH:mm 2012-12-25
	 * 
	 */
	public static String getDate(String format) {
		SimpleDateFormat simple = new SimpleDateFormat(format);
		return simple.format(calendar.getTime());
	}

	/**
	 * 
	 * @return yyyy-MM-dd HH:mm 2012-12-29 23:47
	 */
	public static String getDateAndMinute() {
		SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		return simple.format(calendar.getTime());
	}

	/**
	 * 
	 * @return yyyy-MM-dd HH:mm:ss 2012-12-29 23:47:36
	 */
	public static String getFullDate() {
		SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return simple.format(calendar.getTime());
	}

	/**
	 * 距离今天多久
	 * 
	 * @param date
	 * @return
	 * 
	 */
	public static String fromToday(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);

		long time = date.getTime() / 1000;
		long now = new Date().getTime() / 1000;
		long ago = now - time;
		if (ago <= ONE_HOUR)
			return ago / ONE_MINUTE + "分钟前";
		else if (ago <= ONE_DAY)
			return ago / ONE_HOUR + "小时" + (ago % ONE_HOUR / ONE_MINUTE)
					+ "分钟前";
		else if (ago <= ONE_DAY * 2)
			return "昨天" + calendar.get(Calendar.HOUR_OF_DAY) + "点"
					+ calendar.get(Calendar.MINUTE) + "分";
		else if (ago <= ONE_DAY * 3)
			return "前天" + calendar.get(Calendar.HOUR_OF_DAY) + "点"
					+ calendar.get(Calendar.MINUTE) + "分";
		else if (ago <= ONE_MONTH) {
			long day = ago / ONE_DAY;
			return day + "天前" + calendar.get(Calendar.HOUR_OF_DAY) + "点"
					+ calendar.get(Calendar.MINUTE) + "分";
		} else if (ago <= ONE_YEAR) {
			long month = ago / ONE_MONTH;
			long day = ago % ONE_MONTH / ONE_DAY;
			return month + "个月" + day + "天前"
					+ calendar.get(Calendar.HOUR_OF_DAY) + "点"
					+ calendar.get(Calendar.MINUTE) + "分";
		} else {
			long year = ago / ONE_YEAR;
			int month = calendar.get(Calendar.MONTH) + 1;// JANUARY which is 0
															// so month+1
			return year + "年前" + month + "月" + calendar.get(Calendar.DATE)
					+ "日";
		}

	}

	/**
	 * 距离截止日期还有多长时间
	 * 
	 * @param date
	 * @return
	 */
	public static String fromDeadline(Date date) {
		long deadline = date.getTime() / 1000;
		long now = (new Date().getTime()) / 1000;
		long remain = deadline - now;
		if (remain <= ONE_HOUR)
			return "只剩下" + remain / ONE_MINUTE + "分钟";
		else if (remain <= ONE_DAY)
			return "只剩下" + remain / ONE_HOUR + "小时"
					+ (remain % ONE_HOUR / ONE_MINUTE) + "分钟";
		else {
			long day = remain / ONE_DAY;
			long hour = remain % ONE_DAY / ONE_HOUR;
			long minute = remain % ONE_DAY % ONE_HOUR / ONE_MINUTE;
			return "只剩下" + day + "天" + hour + "小时" + minute + "分钟";
		}

	}

	/**
	 * 距离截止日期还有多长时间
	 *
	 * @param time
	 * @return
	 */
	public static String fromDeadline(long time) {
		long deadline = time / 1000;
		long now = (new Date().getTime()) / 1000;
		long remain = deadline - now;
		if (remain <= ONE_HOUR)
			return "只剩" + remain / ONE_MINUTE + "分钟";
		else if (remain <= ONE_DAY)
			return "只剩" + remain / ONE_HOUR + "小时" + (remain % ONE_HOUR / ONE_MINUTE) + "分钟";
		else {
			long day = remain / ONE_DAY;
			long hour = remain % ONE_DAY / ONE_HOUR;
			long minute = remain % ONE_DAY % ONE_HOUR / ONE_MINUTE;
			return "剩" + day + "天";
		}

	}

	/**
	 * 倒计时
	 * 
	 * @return
	 */
	public static Long[] timesCountDown(long time) {
		Long[] times = null;
		long day = (time / 1000) / ONE_DAY;
		long hour = (time / 1000) % ONE_DAY / ONE_HOUR;
		long minute = (time / 1000) % ONE_HOUR / ONE_MINUTE;
		long second = (time / 1000) % ONE_MINUTE;
		times = new Long[] { day, hour, minute, second };
		return times;
	}

	/**
	 * 距离今天的绝对时间
	 * 
	 * @param date
	 * @return
	 */
	public static String toToday(Date date) {
		long time = date.getTime() / 1000;
		long now = (new Date().getTime()) / 1000;
		long ago = now - time;
		if (ago <= ONE_HOUR)
			return ago / ONE_MINUTE + "分钟";
		else if (ago <= ONE_DAY)
			return ago / ONE_HOUR + "小时" + (ago % ONE_HOUR / ONE_MINUTE) + "分钟";
		else if (ago <= ONE_DAY * 2)
			return "昨天" + (ago - ONE_DAY) / ONE_HOUR + "点" + (ago - ONE_DAY)
					% ONE_HOUR / ONE_MINUTE + "分";
		else if (ago <= ONE_DAY * 3) {
			long hour = ago - ONE_DAY * 2;
			return "前天" + hour / ONE_HOUR + "点" + hour % ONE_HOUR / ONE_MINUTE
					+ "分";
		} else if (ago <= ONE_MONTH) {
			long day = ago / ONE_DAY;
			long hour = ago % ONE_DAY / ONE_HOUR;
			long minute = ago % ONE_DAY % ONE_HOUR / ONE_MINUTE;
			return day + "天前" + hour + "点" + minute + "分";
		} else if (ago <= ONE_YEAR) {
			long month = ago / ONE_MONTH;
			long day = ago % ONE_MONTH / ONE_DAY;
			long hour = ago % ONE_MONTH % ONE_DAY / ONE_HOUR;
			long minute = ago % ONE_MONTH % ONE_DAY % ONE_HOUR / ONE_MINUTE;
			return month + "个月" + day + "天" + hour + "点" + minute + "分前";
		} else {
			long year = ago / ONE_YEAR;
			long month = ago % ONE_YEAR / ONE_MONTH;
			long day = ago % ONE_YEAR % ONE_MONTH / ONE_DAY;
			return year + "年前" + month + "月" + day + "天";
		}

	}

	public static String getYear() {
		return calendar.get(Calendar.YEAR) + "";
	}

	public static String getMonth() {
		int month = calendar.get(Calendar.MONTH) + 1;
		return month + "";
	}

	public static String getDay() {
		return calendar.get(Calendar.DATE) + "";
	}

	public static String get24Hour() {
		return calendar.get(Calendar.HOUR_OF_DAY) + "";
	}

	public static String getMinute() {
		return calendar.get(Calendar.MINUTE) + "";
	}

	public static String getSecond() {
		return calendar.get(Calendar.SECOND) + "";
	}

	/**
	 * 根据年月日获取年龄
	 * 
	 * @param year
	 *            年
	 * @param month
	 *            月
	 * @param day
	 *            日
	 * @return
	 */
	public static int getAge(int year, int month, int day) {
		int age = 0;
		Calendar calendar = Calendar.getInstance();
		if (calendar.get(Calendar.YEAR) == year) {
			if (calendar.get(Calendar.MONTH) == month) {
				if (calendar.get(Calendar.DAY_OF_MONTH) >= day) {
					age = calendar.get(Calendar.YEAR) - year + 1;
				} else {
					age = calendar.get(Calendar.YEAR) - year;
				}
			} else if (calendar.get(Calendar.MONTH) > month) {
				age = calendar.get(Calendar.YEAR) - year + 1;
			} else {
				age = calendar.get(Calendar.YEAR) - year;
			}
		} else {
			age = calendar.get(Calendar.YEAR) - year;
		}
		if (age < 0) {
			return 0;
		}
		return age;
	}

	/**
	 * 根据月日获取星座
	 * 
	 * @param month
	 *            月
	 * @param day
	 *            日
	 * @return
	 */
	public static String getConstellation(int month, int day) {
		if ((month == 1 && day >= 20) || (month == 2 && day <= 18)) {
			return "水瓶座";
		} else if ((month == 2 && day >= 19) || (month == 3 && day <= 20)) {
			return "双鱼座";
		} else if ((month == 3 && day >= 21) || (month == 4 && day <= 19)) {
			return "白羊座";
		} else if ((month == 4 && day >= 20) || (month == 5 && day <= 20)) {
			return "金牛座";
		} else if ((month == 5 && day >= 21) || (month == 6 && day <= 21)) {
			return "双子座";
		} else if ((month == 6 && day >= 22) || (month == 7 && day <= 22)) {
			return "巨蟹座";
		} else if ((month == 7 && day >= 23) || (month == 8 && day <= 22)) {
			return "狮子座";
		} else if ((month == 8 && day >= 23) || (month == 9 && day <= 22)) {
			return "处女座";
		} else if ((month == 9 && day >= 23) || (month == 10 && day <= 23)) {
			return "天秤座";
		} else if ((month == 10 && day >= 24) || (month == 11 && day <= 22)) {
			return "天蝎座";
		} else if ((month == 11 && day >= 23) || (month == 12 && day <= 21)) {
			return "射手座";
		} else if ((((month == 12) && (day > 22)))
				|| (((month == 1) && (day < 20)))) {
			return "摩羯座";
		}
		return "";
	}

	public static String getTime(long timeInMillis, SimpleDateFormat dateFormat) {
		return dateFormat.format(new Date(timeInMillis));
	}

	public static String getTime(long timeInMillis) {
		return getTime(timeInMillis, DEFAULT_DATE_FORMAT);
	}

	/**
	 * 获得当前时间的毫秒
	 * 
	 * @return
	 */
	public static long getCurrentTimeInLong() {
		return System.currentTimeMillis();
	}

	/**
	 * 获得当前时间以毫秒为单位，格式是DEFAULT_DATE_FORMAT
	 * 
	 * @return
	 */
	public static String getCurrentTimeInString() {
		return getTime(getCurrentTimeInLong());
	}

	public static String getCurrentTimeInString(SimpleDateFormat dateFormat) {
		return getTime(getCurrentTimeInLong(), dateFormat);
	}

	/**
	 * 将Date转换成int
	 * 
	 * @return
	 */
	public static int stringToInt(String date) {

		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
			// Date mydate = sdf.parse(sdf.format(date));
			Date mydate = sdf.parse(date);
			long strTime = mydate.getTime();

			// strTime = strTime.substring(0, 10);
			int time = (int) (strTime / 1000);

			return time;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return 0;
	}

	public static double stringToDouble(String date) {

		double time = 0;
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
			// Date mydate = sdf.parse(sdf.format(date));
			Date mydate = sdf.parse(date);
			String strTime = mydate.getTime() + "";
			time = Double.parseDouble(strTime);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return time;
	}

	/**
	 * 将int时间转成yyyy-MM-dd HH:mm:ss'(24小时制)
	 * 
	 * @return
	 */
	public static String TimeStamp2Date(String timestampString, String formats) {
		Long timestamp = Long.parseLong(timestampString) * 1000;
		String date = new SimpleDateFormat(formats).format(new Date(timestamp));
		return date;
	}

	public static int DateToInt(Date time) {
		SimpleDateFormat formatter;
		formatter = new SimpleDateFormat("yyyyMMdd");
		String ctime = formatter.format(time);

		return stringToInt(ctime);
	}

	public static int intToDate(int time) {
		SimpleDateFormat formatter;
		formatter = new SimpleDateFormat("yyyyMMdd");
		String ctime = formatter.format(time);

		return stringToInt(ctime);
	}

	public static String formatDate(Context context, long date) {
		@SuppressWarnings("deprecation")
		int format_flags = android.text.format.DateUtils.FORMAT_NO_NOON_MIDNIGHT
				| android.text.format.DateUtils.FORMAT_ABBREV_ALL
				| android.text.format.DateUtils.FORMAT_CAP_AMPM
				| android.text.format.DateUtils.FORMAT_SHOW_DATE
				| android.text.format.DateUtils.FORMAT_SHOW_DATE
				| android.text.format.DateUtils.FORMAT_SHOW_TIME;
		return android.text.format.DateUtils.formatDateTime(context, date,
				format_flags);
	}

	/**
	 * 将java.util.Date 格式转换为字符串格式'yyyy-MM-dd HH:mm:ss'(24小时制)<br>
	 * 如Sat May 11 17:24:21 CST 2002 to '2002-05-11 17:24:21'<br>
	 * 
	 * @param time
	 *            Date 日期<br>
	 * @return String 字符串<br>
	 */

	public static String dateToString(Date time) {
		SimpleDateFormat formatter;
		formatter = new SimpleDateFormat(" yyyy-MM-dd HH:mm:ss ");
		String ctime = formatter.format(time);

		return ctime;
	}

	/**
	 * 将java.util.Date 格式转换为字符串格式'yyyy-MM-dd HH:mm:ss a'(12小时制)<br>
	 * 如Sat May 11 17:23:22 CST 2002 to '2002-05-11 05:23:22 下午'<br>
	 * 
	 * @param time
	 *            Date 日期<br>
	 * @param x
	 *            int 任意整数如：1<br>
	 * @return String 字符串<br>
	 */
	public static String dateToString(Date time, int x) {
		SimpleDateFormat formatter;
		formatter = new SimpleDateFormat(" yyyy-MM-dd KK:mm:ss a ");
		String ctime = formatter.format(time);

		return ctime;
	}

	/**
	 * 取系统当前时间:返回只值为如下形式 2002-10-30 20:24:39
	 * 
	 * @return String
	 */
	public static String Now() {
		return dateToString(new Date());
	}

	/**
	 * 取系统当前时间:返回只值为如下形式 2002-10-30 08:28:56 下午
	 * 
	 * @param hour
	 *            为任意整数
	 * @return String
	 */
	public static String Now(int hour) {
		return dateToString(new Date(), hour);
	}

	/**
	 * 取系统当前时间:返回值为如下形式 2002-10-30
	 * 
	 * @return String
	 */
	public static String getYYYY_MM_DD() {
		return dateToString(new Date()).substring(0, 10);

	}

	/**
	 * 取系统给定时间:返回值为如下形式 2002-10-30
	 * 
	 * @return String
	 */
	public static String getYYYY_MM_DD(String date) {
		return date.substring(0, 10);

	}

	/**
	 * "yyyy-MM-dd HH:mm:ss"
	 * 
	 * @return
	 */
	public static String getNow() {
		String nowTime = null;
		Date rightNow = new Date();
		DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		nowTime = format1.format(rightNow);
		return nowTime;
	}

	/**
	 * yyyy-MM-dd
	 * 
	 * @return
	 */
	public static String getNow1() {
		String nowTime = null;
		Date rightNow = new Date();
		DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
		nowTime = format1.format(rightNow);
		return nowTime;

	}

	/**
	 * 获得指定日期的前一天
	 * 
	 * @param specifiedDay
	 * @return
	 * @throws Exception
	 */
	public static String getSpecifiedDayBefore(String specifiedDay) {
		Calendar c = Calendar.getInstance();
		Date date = null;
		try {
			date = new SimpleDateFormat("yy-MM-dd").parse(specifiedDay);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		c.setTime(date);
		int day = c.get(Calendar.DATE);
		c.set(Calendar.DATE, day - 1);

		String dayBefore = new SimpleDateFormat("yyyy-MM-dd").format(c
				.getTime());
		return dayBefore;
	}


	/**
	 * 获得指定日期的后一天
	 *
	 * @param specifiedDay
	 * @return
	 */
	public static String getSpecifiedDayAfter(String specifiedDay, int n) {
		Calendar c = Calendar.getInstance();
		Date date = null;
		try {
			date = new SimpleDateFormat("yy-MM-dd").parse(specifiedDay);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		c.setTime(date);
		int day = c.get(Calendar.DATE);
		c.set(Calendar.DATE, day + n);

		String dayAfter = new SimpleDateFormat("yyyy-MM-dd")
				.format(c.getTime());
		return dayAfter;
	}
	/**
	 *字符串的日期格式的计算
	 */
	public static int daysBetween(String smdate, String bdate) throws ParseException {
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.setTime(sdf.parse(smdate));
		long time1 = cal.getTimeInMillis();
		cal.setTime(sdf.parse(bdate));
		long time2 = cal.getTimeInMillis();
		long between_days=(time2-time1)/(1000*3600*24);

		return Integer.parseInt(String.valueOf(between_days));
	}

	/**
	 * 获取今天往后一周的日期（几月几号）
	 */
//	public static List<String> getSevenDate() {
//		List<String> dates = new ArrayList<String>();
//		final Calendar c = Calendar.getInstance();
//		c.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
//
//
//		for (int i = 0; i < 7; i++) {
//			mYear = String.valueOf(c.get(Calendar.YEAR));// 获取当前年份
//			mMonth = String.valueOf(c.get(Calendar.MONTH) + 1);// 获取当前月份
//			mDay = String.valueOf(c.get(Calendar.DAY_OF_MONTH) + i);// 获取当前日份的日期号码
//			if (Integer.parseInt(mDay) > MaxDayFromDay_OF_MONTH(Integer.parseInt(mYear), (i + 1))) {
//				mDay = String.valueOf(MaxDayFromDay_OF_MONTH(Integer.parseInt(mYear), (i + 1)));
//			}
//			String date = mMonth + "月" + mDay + "日";
//			dates.add(date);
//		}
//		return dates;
//	}


	/**
	 * 获取今天往后一周的集合
	 */
	public static List<String> getSevenDate() {
		String date = "";
		List<String> weeksList = new ArrayList<String>();
		List<String> dateList = get7Date();
		for (String s : dateList) {
			if (s.equals(getNow1())) {
				date = "今天";
			} else {
				SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
				Calendar c = Calendar.getInstance();
				try {
					c.setTime(format.parse(s));
				} catch (ParseException e) {

				}
				date = String.valueOf(c.get(Calendar.DAY_OF_MONTH));
			}
			weeksList.add(date);
		}
		return weeksList;
	}

	/**
	 * 获取今天往后一周的集合
	 */
	public static List<String> getSevenWeekDay() {
		String week = "";
		List<String> weeksList = new ArrayList<String>();
		List<String> dateList = get7Date();
		for (String s : dateList) {
			week = getEngWeekDayByTime(s);
			weeksList.add(week);
		}
		return weeksList;
	}

	/**
	 * 获取从当天开始往后7天日期
	 * @return
     */
	public static List<String> get7Date() {
		List<String> dates = new ArrayList<String>();
		final Calendar c = Calendar.getInstance();
		c.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
		SimpleDateFormat sim = new SimpleDateFormat(
				"yyyy-MM-dd");
		String date = sim.format(c.getTime());
		dates.add(date);
		for (int i = 0; i < 6; i++) {
			c.add(Calendar.DAY_OF_MONTH, 1);
			date = sim.format(c.getTime());
			dates.add(date);
		}
		return dates;
	}

	/**
	 * 得到当年当月的最大日期
	 **/
	public static int MaxDayFromDay_OF_MONTH(int year, int month) {
		Calendar time = Calendar.getInstance();
		time.clear();
		time.set(Calendar.YEAR, year);
		time.set(Calendar.MONTH, month - 1);//注意,Calendar对象默认一月为0
		int day = time.getActualMaximum(Calendar.DAY_OF_MONTH);//本月份的天数
		return day;
	}
	public static int getCurrentHour(long time){
		Calendar c = Calendar.getInstance();
        c.setTimeInMillis(time);
		int hour=c.get(Calendar.HOUR_OF_DAY);
        return hour;
	}
	/**
	 * 比较两个日期的大小，日期格式为yyyy-MM-dd
	 *
	 * @param str1 the first date
	 * @param str2 the second date
	 * @return true <br/>false
	 */
	public static boolean isDateOneBigger(String str1, String str2) {
		boolean isBigger = false;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date dt1 = null;
		Date dt2 = null;
		try {
			dt1 = sdf.parse(str1);
			dt2 = sdf.parse(str2);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		if (dt1.getTime() > dt2.getTime()) {
			isBigger = true;
		} else if (dt1.getTime() < dt2.getTime()) {
			isBigger = false;
		}
		return isBigger;
	}

}
